﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TrainingsRequests>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TrainingsRequests>>" %>
<%@ Import Namespace="CRM.Resourses" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsRequest";
                                        settings.KeyFieldName = "IdTrainingsRequest";
                                        settings.CallbackRouteValues = new { Controller = "TC", Action = "TrainingsRequestsPartial" };
                                        settings.SettingsPager.PageSize = 20;


                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = "#";
                                        //    column.SetDataItemTemplateContent(c => ViewContext.Writer.Write(
                                        //        Html.ActionLink(Resourses.TrainingsRequestEdit, "TrainingsRequestEdit", new { IdTrainingsRequest = DataBinder.Eval(c.DataItem, "IdTrainingsRequest") })
                                        //        //+ "&nbsp;" 
                                        //        //+ Html.ActionLink("Удалить", "TrainingsCoursesDelete", new { idTrainingsCourse = DataBinder.Eval(c.DataItem, "IdTrainingsCourse") },
                                        //        //                new { onclick = "return confirm('Удалить учебный курс?')" })
                                        //                                               ));
                                            
                                        //    column.Settings.AllowDragDrop = DefaultBoolean.False;
                                        //    column.Settings.AllowSort = DefaultBoolean.False;
                                        //    //column.Width = 70;
                                        //});

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsRequestNumber; ;
                                            column.FieldName = "IdTrainingsRequest";
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
                                            //String urlFormatString = Url.Action("TrainingsRequestEdit", "TC", new RouteValueDictionary(new { IdTrainingsRequest = "{0}"}));
                                            String urlFormatString = Url.Action("TrainingsRequestDetails", "TC", new RouteValueDictionary(new { IdTrainingsRequest = "{0}" }));
                                            properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                            properties.TextField = "IdTrainingsRequest";
                                        });

                                        
                                        
                                        //дата регистрицаа заявки
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsRegisterDate;
                                            column.FieldName = "RequestDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });

                                        //Название курса
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCourse;
                                            column.FieldName = "CourseNameExt";
                                        });

                                        ////Добавление комбобоксов
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.FieldName = "IdTrainingsSchedule";

                                        //    column.Caption = Resourses.TrainingsCourse;
                                        //    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                        //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                        //    if (comboBoxProperties != null)
                                        //    {
                                        //        comboBoxProperties.DataSource = DB.TrainingsSchedules;
                                        //        comboBoxProperties.TextField = "CourseName";
                                        //        comboBoxProperties.ValueField = "IdTrainingsSchedule";
                                        //        comboBoxProperties.ValueType = typeof(int);
                                        //    }
                                        //});
                                        ////конец комбобокса

                                        ////Добавление комбобоксов
                                        ////дата курса
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.FieldName = "IdTrainingsSchedule";
                                        //    column.Caption = Resourses.TrainingsScheduleDate;
                                        //    //column.Caption = "Точно оно?";
                                        //    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                        //    column.PropertiesEdit.DisplayFormatString = "d";
                                        //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                        //    if (comboBoxProperties != null)
                                        //    {
                                        //        comboBoxProperties.DisplayFormatString = "d";
                                        //        comboBoxProperties.DisplayFormatInEditMode = true;
                                        //        comboBoxProperties.DataSource = DB.TrainingsSchedules;
                                        //        comboBoxProperties.TextField = "PlannedDate";
                                        //        comboBoxProperties.ValueField = "IdTrainingsSchedule";
                                        //        comboBoxProperties.ValueType = typeof(int);
                                        //        comboBoxProperties.TextFormatString = "d";
                                        //    }
                                        //});
                                        ////конец комбобокса

                                        //дата курса
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsScheduleDate;
                                            column.FieldName = "CourseDateExt";
                                            //column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });
                                        
                                        //компания
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCompany;
                                            column.FieldName = "IdCustomer";
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                            var properties = column.PropertiesEdit as HyperLinkProperties;
                                            //String urlFormatString = Url.Action("TrainingsRequestEdit", "TC", new RouteValueDictionary(new { IdTrainingsRequest = "{0}"}));
                                            var urlFormatString = Url.Action("Details", "Customers", new RouteValueDictionary(new { id = "{0}" }));
                                            properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                            properties.TextField = "CompanyExt";
                                        });

                                        //контакстное лицо
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsContactName;
                                            column.FieldName = "ContactNameExt";
                                        });

                                        //контактный телефон
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsContactPhone;
                                            column.FieldName = "ContactPhoneExt";
                                        });

                                        //email
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsContactEmail;
                                            column.FieldName = "ContactEmailExt";
                                        });

                                        //комментарии
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsComments;
                                            column.FieldName = "Comments";
                                        });

                                        //Добавление локализованного комбобокса
                                        //Статус заявки
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsRequestsStatus";
                                            column.Caption = Resourses.TrainingRequestsStatus;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var statusesCol = new CRM.Database.Model.TrainingRequestsStatusesCollection();
                                                comboBoxProperties.DataSource = statusesCol.TrainingRequestsStatusesList;
                                                //comboBoxProperties.DataSource = DB.GetLocalizedTrainingRequestsStatusesNames(Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdTrainingRequestsStatus";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        //тип учебного курса
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsRequestsType;
                                            column.FieldName = "RequestType";
                                        });

                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = false;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = false;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        //settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "TC", Action = "TrainingsRequestsPartialUpdate" };
                                        //settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TC", Action = "TrainingsRequestsPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TC", Action = "TrainingsRequestsPartialDelete" };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                        
                                        
                                     }).Bind(Model).GetHtml();
%>
